package com.iyundao.io.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.iyundao.io.model.SysPermission;
import org.springframework.stereotype.Repository;

@Repository
public class SysPermissionSqlProvider {

    public String insertSelective(SysPermission record) {
        BEGIN();
        INSERT_INTO("sys_permission");
        
        if (record.getSid() != null) {
            VALUES("sid", "#{sid,jdbcType=CHAR}");
        }
        
        if (record.getRealName() != null) {
            VALUES("real_name", "#{realName,jdbcType=VARCHAR}");
        }
        
        if (record.getShowName() != null) {
            VALUES("show_name", "#{showName,jdbcType=VARCHAR}");
        }
        
        if (record.getFlag() != null) {
            VALUES("flag", "#{flag,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateDate() != null) {
            VALUES("create_date", "#{createDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCreateId() != null) {
            VALUES("create_id", "#{createId,jdbcType=CHAR}");
        }
        
        if (record.getOrdeBy() != null) {
            VALUES("orde_by", "#{ordeBy,jdbcType=TINYINT}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(SysPermission record) {
        BEGIN();
        UPDATE("sys_permission");
        
        if (record.getRealName() != null) {
            SET("real_name = #{realName,jdbcType=VARCHAR}");
        }
        
        if (record.getShowName() != null) {
            SET("show_name = #{showName,jdbcType=VARCHAR}");
        }
        
        if (record.getFlag() != null) {
            SET("flag = #{flag,jdbcType=VARCHAR}");
        }
        
        if (record.getCreateDate() != null) {
            SET("create_date = #{createDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCreateId() != null) {
            SET("create_id = #{createId,jdbcType=CHAR}");
        }
        
        if (record.getOrdeBy() != null) {
            SET("orde_by = #{ordeBy,jdbcType=TINYINT}");
        }
        
        WHERE("sid = #{sid,jdbcType=CHAR}");
        
        return SQL();
    }
}